// 在 assessment.js 中导入 assessment_list
import assessment_list from '../store/assessment_list';

// 定义参数类型
type Job = string;

export function assessment(job:Job) {
    //const user_email = "1297562701@qq.com";
    // 创建请求体数据
    const requestData = {
        user_email: localStorage.getItem("userEmail"),
        job: job,
    };

    fetch('http://127.0.0.1:8000/assessment', {
        method: 'POST',
        body: new URLSearchParams(requestData), // 将请求体数据转换为适合 FastAPI 的格式
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
        },
    })
        .then(response => {
            if (!response.ok) {
                throw new Error('Network response was not ok');
            }
            return response.json();
        })
        .then(data => {
            console.log(data);
            assessment_list.value = data.result;
        })
        .catch(error => {
            console.error('Error:', error);
        });
}
